package com.dao.hibernate;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;

import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.Session;

import com.dao.EventoFotoDAO;
import com.model.EventoFoto;

public class EventoFotoDAOHibernate implements EventoFotoDAO {
	
	private Session sessao;
	private EntityManagerFactory emf = null;
	

   	
	@Override
	public void registraEventoFoto(EventoFoto eventoFoto) {
		this.sessao.save(eventoFoto);
		
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<EventoFoto> getLista() {
		Criteria lista = sessao.createCriteria(EventoFoto.class);
		return lista.list();
	}

	@Override
	public void excluir(EventoFoto eventoFoto) {
		this.sessao.delete(eventoFoto);
		
	}

	public Session getSessao() {
		return sessao;
	}

	public void setSessao(Session sessao) {
		this.sessao = sessao;
	}
	
	 public EntityManager getEntityManager() {
	        return emf.createEntityManager();
	    }
	
	@Override
	public EventoFoto localizaEventoFoto() {
		Integer photoId = 11;

		Query consulta = this.sessao.createQuery("from EventoFoto e where e.photoId = :photoId");
		consulta.setInteger("photoId", photoId);
		System.out.println("--------------------------------------------------------------"+consulta);
		return (EventoFoto) consulta.uniqueResult();
				
	}
	
}
